//
//  TXVideoViewController.swift
//  TXPlayerDemo
//
//  Created by looha on 2021/8/30.
//

import UIKit
import TXLiteAVSDK_Professional

class TXVideoViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        let downloadingBtn = UIButton(frame: CGRect(x: 100, y: 100, width: 200, height: 100))
        downloadingBtn.setTitle("模拟正在下载", for: .normal)
        downloadingBtn.setTitleColor(.black, for: .normal)
        downloadingBtn.addTarget(self, action: #selector(onDownloadProgress), for: .touchUpInside)
        view.addSubview(downloadingBtn)
        
        let finishBtn = UIButton(frame: CGRect(x: 100, y: 200, width: 200, height: 100))
        finishBtn.setTitle("模拟下载完成", for: .normal)
        finishBtn.setTitleColor(.black, for: .normal)
        finishBtn.addTarget(self, action: #selector(onDownloadFinish), for: .touchUpInside)
        view.addSubview(finishBtn)
    }
    
    @objc
    private func onDownloadProgress(){
        
        //主视频下载信息
        let mainVideoInfo = TXVodDownloadMediaInfo()
        mainVideoInfo.downloadSize = 2040109465 //约为1.9G
        
        //辅视频下载大小
        let subVideoInfo = TXVodDownloadMediaInfo()
        subVideoInfo.downloadSize = 1 //1byte


        //不会crash
        let totalDownloadSize =  mainVideoInfo.downloadSize + subVideoInfo.downloadSize
        
        debugPrint("totalDownloadSize = \(totalDownloadSize)")
    }
    
    @objc
    private func onDownloadFinish(){
        
        
        //主视频下载信息
        let mainVideoInfo = TXVodDownloadMediaInfo()
        mainVideoInfo.downloadSize = 2040109465 //约为1.9G
        
        //辅视频下载大小
        let subVideoInfo = TXVodDownloadMediaInfo()
        subVideoInfo.downloadSize = 1073741824 //1G


        //溢出 crash
        let totalDownloadSize =  mainVideoInfo.downloadSize + subVideoInfo.downloadSize
        
        //溢出，值错误
        //let totalDownloadSize =  mainVideoInfo.downloadSize &+ subVideoInfo.downloadSize

        debugPrint("totalDownloadSize = \(totalDownloadSize)")
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
